package com.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.model.dao.ScoreDao;

import com.model.pojo.User;

/**
 * Servlet implementation class ScoreTop
 */
public class ScoreTop extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ScoreTop() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=utf-8");
	    String score = request.getParameter("countdown");
	    HttpSession session = request.getSession();
	    String username = (String)session.getAttribute("username");
	     System.out.println(username);
	    System.out.println(score);
	    int score1 = Integer.parseInt(score);
	    
	  new ScoreDao().insert(username, score1);
	  
	  
	  
//	    String command =  request.getParameter("command");
//		String username = request.getParameter("username");
//		String password = request.getParameter("password");
//		
//		System.out.println(username+password);
//		
//		switch(command){
//		case "login":
//		User user = new ScoreDao().login(username, password);
//		if(user!=null){
//	   response.sendRedirect("index.html");
//		}else{
//		response.sendRedirect("error.html");
//		}
//		break;
//		
//		case"":
//			
//		
//		}	
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
